home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
news
/
readers
/
skim-0.8
/
skim-0
/
skim-0.8.4
/
GetSelectedArticlesInGroup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-18
|
7KB
|
239 lines
/*
* NAME
* GetSelectedArticlesInGroup.c
* USAGE
* Usage: GetSelectedArticlesInGroup Group
* DESCRIPTION
* Retrieve the selected articles from the news server.
* OUTPUT
* Every article is stored in a separate file in the directory
* $SKIMDIR/Articles. The file name is GroupName.ArticleNumber.
* COPYRIGHT
* Skim - Off-line news reading package optimized for slow lines.
* Copyright (C) 1996 Rene W.J. Pijlman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* VERSION
* Skim version 0.8.4.
*/
#include <unistd.h>
#include <string.h>
#include "VarBuf.h"
#include "Skim.h"
#include "SkimUtils.h"
#include "NNTPStream.h"
#include "StandardIO.h"
FILE_ID("$Header: /home/rene/sys/CVS_MasterSourceRepository/skim/GetSelectedArticlesInGroup.c,v 1.6 1996/02/18 11:40:18 rene Exp $");
int main( int argc, char * argv[] )
{
VarBuf SubjectsFileName = VBCreate();
StandardIO SubjectsFile = SIOCreate();
if ( argc != 2 )
{
SIOPrintf( StandardError, "%s\n",
"Usage: GetSelectedArticlesInGroup Group" );
exit( EXIT_FAILURE );
}
if ( strlen(argv[1]) > 0 )
{
VBPrintf( SubjectsFileName, "%s/Subjects/%s", SkimDirectory(),
argv[1] );
SIOFileOpenVB( SubjectsFile, SubjectsFileName, OpenModeReadIgnore );
if ( SIOIsOpenForRead(SubjectsFile) )
{
VarBuf SubjectLine = VBCreate();
VarBuf ArticleFileName = VBCreate();
VarBuf IndexFileName = VBCreate();
VarBuf SkippedFileName = VBCreate();
VarBuf Selection = VBCreate();
VarBuf ArticleNumber = VBCreate();
StandardIO SkippedFile = NULL;
StandardIO Index = NULL;
StandardIO NewsServer = NULL;
StandardIO ArticleFile = SIOCreate();
VBPrintf( IndexFileName, "%s/Indexes/Articles/%s", SkimDirectory(),
argv[1] );
VBPrintf( SkippedFileName, "%s/Skipped/%s", SkimDirectory(),
argv[1] );
while ( VBReadLine( SubjectLine, SubjectsFile, WITHOUT_NEWLINE ) )
{
if ( !AppendFieldFromFixedRecord( Selection, SubjectLine,
OffsetOfSelection(),
LengthSelection,
NULL ) )
{
SIOPrintf( StandardError,
"Incorrect format: no 'Selection' field: %s\n",
VBAsString(SubjectLine));
exit( EXIT_FAILURE );
}
if ( *VBAsString(Selection) == Selected )
{
Boolean ArticleIsAvailable;
VarBuf Command = VBCreate();
VarBuf ArticleSkipped = VBCreate();
VarBuf SubjectOfArticle = VBCreate();
if ( NewsServer == NULL )
{
NewsServer = NNTPStreamOpen();
}
VBReset( Command );
VBPrintf( Command, "group %s", argv[1] );
/* Make group current. */
SIOInternetCommand( NewsServer, VBAsString( Command ) );
CheckStatusResponse( NewsServer, argv[1], "2", NULL,
TERMINATE_ON_ERROR );
if (!AppendFieldFromFixedRecord( ArticleNumber, SubjectLine,
OffsetOfArticleNumber(),
LengthArticleNumber,
VBRemoveTrailingBlanks ) )
{
SIOPrintf( StandardError,
"Incorrect format: No article number: %s\n",
VBAsString(SubjectLine));
exit( EXIT_FAILURE );
}
VBPrintf( ArticleFileName, "%s/Articles/%s.%V",
SkimDirectory(), argv[1], ArticleNumber );
/* Make group current. */
VBReset( Command );
VBPrintf( Command, "article %V", ArticleNumber );
SIOInternetCommand( NewsServer, VBAsString(Command) );
/*
* Prepare a message which may be printed by
* CheckStatusResponse().
*/
if (!AppendFieldFromFixedRecord( SubjectOfArticle, SubjectLine,
OffsetOfSubject(),
VARIABLE_LENGTH,
VBRemoveTrailingBlanks) )
{
SIOPrintf( StandardError,
"Incorrect format: No subject: %s\n",
VBAsString(SubjectLine));
exit( EXIT_FAILURE );
}
VBPrintf( ArticleSkipped,
"Warning: skipped article %V in newsgroup %s\nSubject: %V.\n\n",
ArticleNumber, argv[1], SubjectOfArticle );
/* Check status response. */
ArticleIsAvailable =
CheckStatusResponse( NewsServer, argv[1], "2",
VBAsString(ArticleSkipped),
DONT_TERMINATE_ON_ERROR );
if ( ArticleIsAvailable )
{
SIOFileOpenVB( ArticleFile, ArticleFileName,
OpenModeWriteDiscardOld );
/* Write the article in a file. */
GetTextResponse( NewsServer, NULL, NULL, ArticleFile,
NULL );
SIOFileClose( ArticleFile );
if ( Index == NULL )
{
Index = SIOCreate();
SIOFileOpenVB( Index, IndexFileName, OpenModeAppend );
}
AddArticleToIndex( ArticleFileName, ArticleNumber, Index );
}
VBDestroy(Command);
VBDestroy( SubjectOfArticle );
VBDestroy( ArticleSkipped );
}
else if ( *VBAsString(Selection) == NotSelected )
{
if ( SkippedFile == NULL )
{
SkippedFile = SIOCreate();
SIOFileOpenVB( SkippedFile, SkippedFileName,
OpenModeAppend );
}
SIOPrintf( SkippedFile, "%V\n", SubjectLine);
}
else
{
SIOPrintf( StandardError,
"Incorrect format: not %c or %c on first position: %V\n",
Selected, NotSelected, SubjectLine );
exit( EXIT_FAILURE );
}
VBReset( ArticleNumber );
VBReset( ArticleFileName );
VBReset( SubjectLine );
VBReset( Selection );
}
NNTPStreamClose( NewsServer );
NewsServer = NULL;
SIODestroy( Index );
SIODestroy(SkippedFile);
SIOFileClose( SubjectsFile );
if ( remove( VBAsString(SubjectsFileName) ) != 0 )
{
SIOPrintf( StandardError, "Error removing %V\n",
SubjectsFileName );
exit( EXIT_FAILURE );
}
VBDestroy(SubjectLine);
VBDestroy(ArticleFileName);
VBDestroy(IndexFileName);
VBDestroy(SkippedFileName);
VBDestroy(Selection);
VBDestroy(ArticleNumber);
SIODestroy(ArticleFile);
}
}
VBDestroy(SubjectsFileName);
SIODestroy(SubjectsFile);
return EXIT_SUCCESS;
}